package 运输配货系统;

import java.util.Scanner;

public class OrderList {

	Order []orderList;
	
	public OrderList(int i) {
		
		
		orderList=new Order[i];
		
		
		
	}
	
	
	                                                        
	public void Initialize(User user,office office1,int n) {  //初始化   n代表改用户的订单个数 
	int k,ii,i;

		for(i=0;i<n;i++)
		{ ii=Order.getCount();
			Order order=new Order(user,office1);
			int jj=Order.getCount();
			if(ii==jj)
			{break;}
			else {
				System.out.println(order.getCount()-1);
			orderList[order.getCount()-1]=order;
			user.setOrderID(order.orderNumber, i);}
		}
		if(i==n) {
		user.orderNumber=n;
		}
		
		else {
			user.orderNumber=i;
			
			Order [] orderList1=new Order[Order.getCount()];
			for(int j=0;j<orderList1.length;j++) {
				orderList1[j]=orderList[j];
				
			}
			
			orderList=orderList1;
		}
		
		
	}
	
	public void Initialize1(UserList userlist,office office1)
	
	{
		for(int i=0;i<userlist.userList.length;i++)
		{
			System.out.println("请为第"+userlist.userList[i].getName()+"先生输入订单数量");
			Scanner input=new Scanner(System.in);
			int n=input.nextInt();
			this.Initialize(userlist.userList[i],office1,n);
		}		
	}
	
	
	public  void AddOrder(User user,office office1) {     //增
		
	Order [] orderList1=new Order[orderList.length+1];
	
	for(int i=0;i<orderList.length;i++)
		orderList1[i]=orderList[i];
		orderList=orderList1;
		orderList[orderList1.length-1]=new Order(user,office1);
		
	}

	public static void  removeOrder(OrderList a,Order b,office office1) {    //删
		int i;
	for( i=0;i<a.orderList.length;i++)
	{
		    if(b==a.orderList[i]) {
		    	break;
		    } 
	}
	
	for(i=i+1;i<a.orderList.length;i++)
	{
		a.orderList[i-1]=a.orderList[i];
		
	}     
	             
	
	Order [] orderList1=new Order[a.orderList.length-1];
	for(int j=0;j<orderList1.length;j++) {
		orderList1[j]=a.orderList[j];
		
	}
	
	a.orderList=orderList1;
	for(int ii=0;ii<office1.cargroup.length;ii++)
		for(int j=0;j<office1.cargroup[ii].a.length;j++)
		{
	       if( Car.toString( b.carNumber).equals(Car.toString(office1.cargroup[ii].a[j].carNumber)))
	    	   office1.cargroup[ii].a[j].bool=false;
		}
	Order.setCount();
	}   
	
public static void update(Order b) {                //改
System.out.println("输入：寄件人名 收件人名 寄件人电话 收件人电话");	
	Scanner input1=new Scanner(System.in);
	String sendName=input1.next();                     //寄件人名
	String receiverName=input1.next();                      //收件人名
	String anumber=input1.next();
	int a[]=new int[11];                           //寄件人电话
	for(int i=0;i<a.length;i++)
		a[i]=anumber.charAt(i)-48;
	String bnumber=input1.next();                              //收件人电话
	int c[]=new int[11];
	for(int i=0;i<c.length;i++)
		c[i]=bnumber.charAt(i)-48;
	b.setSendName(sendName);
	b.setReceivrName(receiverName);
	b.setTelephoneNumber_sendName(a);
	b.setTelephoneNumber_receiver(c);
	b.setFirstAddress();
	b.setlastAddress();
	
                                                       }





public static void search(Order b) {                //查
	
	System.out.println("用户Id:"+b.getUserID()+"订单编号："+b.getOrderNumber());
	System.out.println("寄件人："+b.getSendName()+"地址:"+b.getFirstAddress()+"电话："+b.getTelephoneNumber_sendName());
	System.out.println("收件人："+b.getReceivrName()+"地址:"+b.getLastAddress()+"电话："+b.getTelephoneNumber_receiverName());

	System.out.println("第"+b.getCarGroupNumber()+"组车"+"车牌号："+b.getCarNumber());
	
	
                                               }

}
	
	
	
	
	
	
	

